- [Instructor] When an operational amplifier is used
in the open-loop configuration without any feedback,
it can be used as a comparator
which looks at the voltage at each of its input terminals
and determines which is the largest of the two.
The comparator outputs the voltage connected
to either the positive or the negative supply rail
to indicate which of the input voltages is higher.
If the voltage at the non-inverting input terminal is
higher than the inverting input terminal,
the comparator will output the voltage
from its positive supply rail.
And if the voltage at the non-inverting input terminal is
the lower of the two, then the comparator will output
the negative supply rail voltage.
The comparator circuit works because
in the open-loop configuration the output voltage
from the op-amp will be equal to its open-loop gain
which is abbreviated as Ao times the difference
between the non-inverting input voltage
and the inverting input voltage.
As the non-inverting input voltage rises
above the inverting input, so the difference
between them is positive, the output will rise
until it reaches the positive supply voltage and saturates.
A similar thing happens in the other direction
when the non-inverting input is less
than the inverting input.
So there difference is negative.
The output voltage will fall until it saturates
at the negative supply voltage.
Since op-amps are designed to have a really high
open-loop voltage gain, often 100 decibels or more,
this linear transition between the two
saturation levels is really steep.
So even a very small difference between
the two input voltages will be enough
to push that output voltage into one
of those two saturation regions.
In fact, that saturation region is narrow enough,
you can basically treat the output as a binary decision
with two possible states, either high or low.
The comparator is acting like a one bit
analog digital converter that looks at how
one analog voltage compares to another
and then outputs a digital one or zero
based on what it sees.
In practice, the inverting terminal of an op-amp
comparator is usually connected to a static
reference voltage which serves as the threshold
for comparison against the input voltage
at the non-inverting input terminal.
This reference voltage can come from a variety
of sources such as a battery or a zener diode
or even just a simple voltage divider
made with two resisters.
To demonstrate that, I've built this circuit
on my breadboard using a pair of one mega ohm resisters
as a voltage divider which will divide down
my five volt power source in half
to generate a 2.5 volt reference voltage.
I've tied the op-amps negative supply rail to ground
and the positive supply rail to the five-volt source.
I'm using a variable power supply to provide
an adjustable input voltage to the comparator circuit
which I'm displaying on channel one
of my oscilloscope in yellow.
Channel two is showing the comparator's
output voltage in blue and channel three is showing
the 2.5 volt reference from the voltage divider in pink.
When the input is below the 2.5 volt threshold,
the comparator outputs zero volts
because I connected the negative supply line to ground.
But as soon as I raise the input voltage
above that threshold, the output jumps up
towards the positive supply voltage of five volts.
As the input signal changes above and below the threshold,
the output signal switches very quickly
between the high and low values accordingly.
The op-amp comparator's ability to act
as a one-bit analog to digital converter
makes it useful for interfacing between
analog sensors and digital micro controllers
like in Arduino or Raspberry Pi.
For example, if I wanted to use a photo diode
to detect whether the lights are on or off in a room,
I need to compare the output voltage
from my photo diode circuit to determine
if it's above or below a certain threshold.
If I was an Arduino micro controller,
that would be easy because an Arduino board has
built-in analog input channels that I can use
to directly measure the sensor's output.
And then I just use some software to determine
whether the measured value is above
or below my threshold.
Now, if I wanted to use another type
of micro-controller platform that doesn't
already have analog inputs, like a Raspberry Pi,
which only has digital inputs,
then I'll need to get a bit more creative.
The digital input on a raspberry pi only expects
to see one of two possible voltages
that each represent a different digital value.
When the input voltage is zero,
that's the low value which represents a digital zero,
and when the input voltage is 3.3 volts,
that represents the high value which is a digital one.
Since I only really care about whether
the photo diode's voltage is above or below a threshold,
this is a perfect time to use an op-amp comparator.
To generate the reference voltage for the comparator
I'll use a variable voltage divider
like a potentiometer so I can adjust
that threshold voltage that I'm using for comparison.
I'll connect the op-amp's positive
and negative supply rails to 3.3 and zero volts
which correspond to the high and low voltage values
that the raspberry pi's digital input pins
used to represent one and zero.
The op-amp will compare the voltages coming
from the photo diode against my threshold
and it will produce high or low outputs
representing a digital one or zero
which I can read using a digital input line
on a raspberry pi.